<?

class indexController extends inabuurt_controller_action{
	
	/*
		dit is de root index van de site
		hier wordt de homepage getoond
	*/
	public function indexAction(){
		
		// doorsturen van request naar de bewonersgroepcontroller
		if($this -> request -> getParam(0) != NULL){
		
			$this -> redirect('/bewonersgroepen/' . $this -> request -> getParam(0));
		
		}
		
		// view settings
		$this -> view -> title = "Bewonersgroepen in Antwerpen | INABUURT.be";
		$this -> view -> addStyle(view::PATH_TO_STYLE.'home.css');
		$this -> view -> addScript("http://www.google.com/jsapi");
		
		$this -> view -> setTpl('index.php');
		
		// gegevens opvragen
		$this -> fotoUpdate();
		$this -> berichtUpdate();
		$this -> nieuwsUpdate();
		$this -> videoUpdate();
		$this -> initKalender();
		
		
		// view renderen
		$this -> view -> render();

		
	}
	
	/*
	Login action 
	@author		Jelle Versele
	
	Hier gebeurt het inloggen
	*/

	public function loginAction(){
		
		
		
	
		$form = new form('frm_login', form::POST);
		$userName = $form -> createElement('frm_username', 'textField');
		$password = $form -> createElement('frm_password', 'textField');
		$hidden = $form -> createElement('frm_rederict', 'textField');
		$password -> addFilter('sha1Encode');
		
		$form -> addElementRange(array($userName, $password, $hidden));
		
		
		
		
		if($form -> isSend()){
		
			$user = new user($this -> conn);
			
			$user -> name = $userName -> getSend();
			$user -> password = $password -> getSend();
			
		
			if($user -> login()){
				
				if($hidden -> getSend() != '/login/'){
					$this -> redirect($hidden -> getSend());			
				}else{
					$this -> redirect('/');
				}
			}else{
			
				$this -> view -> setTpl('error.php');
				$this -> view -> errorText = "Je paswoord en/of gebruikersnaam is fout, propeer het eens opnieuw";
				$this -> view -> render();
				
				return;
			}
			
		}
		
		
	}
	
	/*
		loguit action 
		@author	Jelle Versele
	*/
	
	public function loguitAction(){
	
		$this -> user -> killSession();
		$this -> redirect('/');
			
		
	
	}
	
	
	private function initKalender(){
	
		$kalender = new kalender($this -> conn);
		
		$kalender -> setJaar(date('o'));
		
		$this -> view -> dagen = $kalender -> getMaand(date('n')) -> getDagen();
		$this -> view -> maand = date('n');
		$this -> view -> jaar = date('o');
	
	
	}
	
	
	private function videoUpdate(){
		require_once('./application/models/videoModel.php');
		$model = videoModel::getInstance($this -> conn);
		$videos = $model -> getLastVideos();
		
		$this -> view -> videos = $videos;
		
	
	}
	
	
	private function fotoUpdate(){
		require_once('./application/models/fotoModel.php');
		$model = fotoModel::getInstance($this -> conn);
		$foto = $model -> fill();

		$this -> view -> fotos = $foto;
		
	
		
		
	}
	private function berichtUpdate(){
		require_once('./application/models/berichtModel.php');
		$berichten = array();
		$model = berichtModel::getInstance($this -> conn);
		$berichten = $model -> fill();
		
		$this -> view -> berichten = $berichten;		
	}
	private function nieuwsUpdate(){
		require_once('./application/models/nieuwsModel.php');
		$nieuws = array();
		$model = nieuwsModel::getInstance($this -> conn);
		$nieuws = $model -> getLimitedNieuws(10);
		
		$this -> view -> nieuwsItems = $nieuws;
	}
	
	
	public function registrerenAction(){
	
		$this -> view -> setTpl('registreren.php');
		$this -> view-> render();
	
	}
	
	
	public function paswoordAction(){
	
		$this -> view -> setTpl('paswoord.php');
		$this -> view-> render();
	
	}
	
	
	
}


?>